package com.action.addrbook;

import com.db.addrbook.CategoryDAO;
import com.db.addrbook.CategoryVO;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

public class CategoryInputAction implements ModelDriven<Object>, Preparable{	

	private CategoryVO cvo;
	private CategoryDAO caDAO;
	
	public void setCaDAO(CategoryDAO caDAO) {
		this.caDAO = caDAO;
	}
	@Override
	public void prepare() throws Exception {
		cvo = new CategoryVO();
	}
	@Override
	public Object getModel() {	
		return cvo;
	}
	
	public String insertCategory(){
		String result = "";	
		try {			
			//System.out.println(cvo.toString());
			caDAO.insertCategory(cvo);
			result = "success";
		} catch (Exception e) {
			System.out.println("CategoryInputAction.insertCategory():"+e.toString());			
			result = "error";
		}
		return result;		
	}
	
	public String updateCategory(){
		String result = "";		
		try {			
			//System.out.println(cvo.toString());
			caDAO.updateCategory(cvo);
			result = "success";
		} catch (Exception e) {
			System.out.println("CategoryInputAction.updateCategory():"+e.toString());
			result = "error";
		}
		return result;		
	}
}
